package com.zkk.web;

import com.alibaba.fastjson.JSON;
import com.zkk.pojo.Account;
import com.zkk.pojo.User;
import com.zkk.service.AccountService;
import com.zkk.service.UserService;
import com.zkk.service.impl.AccountServiceImpl;
import com.zkk.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/openAccount")
public class openAccountServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String telephone = req.getParameter("telephone");
        String id_number = req.getParameter("id_number");
        String username = req.getParameter("username");
        Account account = new Account();
        account.setUsername(username);
        account.setId_number(id_number);
        account.setTelephone(telephone);
        AccountService accountService = new AccountServiceImpl();
        if(accountService.queryAccount(id_number)==null){
            int i = accountService.addAccount(account);
            req.getSession().setAttribute("username",username);
            String s = JSON.toJSONString(telephone);
            resp.getWriter().write(s);
        }else {
            String s = JSON.toJSONString(1);
            resp.getWriter().write(s);

        }
    }
}
